package com.jt.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jt.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    /**
     * 基于用户名获取用户信息
     * @param username
     * @return
     */
    @Select("select id,username,password,status " +
            "from tb_users " +
            "where username=#{username}")
    User selectUserByUsername (String username);

//    @Select("select permission from tb_menus where id in " +
//            "(select menu_id from tb_role_menus where role_id in " +
//            "(select role_id from tb_user_roles where user_id = #{userId}))")
    @Select("select m.permission from tb_user_roles ur join tb_role_menus rm on ur.role_id = rm.role_id " +
            "join tb_menus m on m.id = rm.menu_id where ur.id = #{userId}")
    List<String> selectUserPermissions(Long userId);


}
